<?php

namespace app\admin\controller;

use think\Controller;

class Tree extends Controller {

    public function index() {
        $listss = db("auth")->order('auth_pid ASC,auth_id ASC')->select();
        $list = $this->tree($listss);
        $this->assign('list', $list);
        return $this->fetch();
    }

    /**
     * 树形分类
     */
    public function tree($data, $pid = 0, $html = "|---", $level = 0) {
        $temp = array();

        foreach ($data as $k => $v) {
            if ($v['auth_pid'] == $pid) {
                $str = str_repeat($html, $level);
                $v['html'] = $str;
                $v['level'] = $level;
                $temp[] = $v;
                $temp = array_merge($temp, self::tree($data, $v['auth_id'], '|---', $level + 1));
                //$treelist[] = self::tree($data, $v['auth_id'], '|---', $count + 1);
            }
        }
        return $temp;
    }

}
